<?php 
	
	class Tfn_model extends CI_Model {
		
		 var $tblName = "vdn";
		 
		function __construct()
		{
			parent::__construct();
		}
		
		function add($record)
		{
			$this->db->insert($this->tblName, $record);
			DB_modification_logs("tfn");
		}
		
		function update($record)
		{	
			$this->db->where('id', $record['id']);
			unset($record['id']);				
			$this->db->update($this->tblName, $record);
			DB_modification_logs("tfn");
		}
		
		function getDetailByID($id)
		{
		  $id = (int)$id;	
		  $sql = "SELECT * FROM " . $this->tblName . " WHERE id = ".$id;
		  return $this->db->query($sql)->row_array();
		}
		
		function getDistinctSkills()
		{
		  $sql = "SELECT distinct skillset FROM " . $this->tblName ." where skillset is not null AND length(skillset) > 0 " ;
		  return $this->db->query($sql)->result();
		}
		
		function batch_update($POST)
		{
			$skillset = $this->input->post('skillset');
 			
			$record = array();
			if( trim($POST['off_hours']) != '' )
			{
				$record['off_hours'] = addslashes($this->input->post('off_hours'));
			}
			if( trim($POST['weekend_off_hours']) != '' ) 
			{
				$record['weekend_off_hours'] = addslashes($this->input->post('weekend_off_hours'));
			}
			
			if( trim($POST['off_hours_playback']) != '' )
			{
				$record['off_hours_playback'] = addslashes($this->path.$this->input->post('off_hours_playback'));
			}
			
			if( trim($POST['business_hours_playback']) != '' ) 
			{
				$record['business_hours_playback'] = addslashes($this->path.$this->input->post('business_hours_playback'));
			}
			
			
			if( count($record) > 0 )
			{
				$this->db->where('skillset', $skillset);
				$this->db->update($this->tblName, $record);			 
				DB_modification_logs("tfn_batch_update"); 	
			}
			else
			{
				$this->session->set_flashdata('userMesg', 'Please select atleast one field to update.');
				$this->session->set_flashdata('error_class', '1');
				redirect($this->uri->segment(1).'/'.$this->uri->segment(2));				
			}
		}
		
		function getListingData($GET, $start, $offset = 20)
		{
 			$where = ' WHERE tfn <> "" ';
			if( isset($GET['tfn']) && trim($GET['tfn']) != '' )
			{
				$where  .= " AND tfn LIKE '%".trim($this->db->escape($GET['tfn']),"'")."%' ";	
			}
			if( isset($GET['skill_id']) && trim($GET['skill_id']) != '' )
			{
				$where  .= " AND skill_id LIKE '%".trim($this->db->escape($GET['skill_id']),"'")."%' ";	
			}
			
			$LIMIT = "LIMIT $start ,  $offset ";
			$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM " . $this->tblName . " {$where} order by tfn {$LIMIT} ";
			$results = $this->db->query($sql)->result();	
			$total_record = $this->common_model->get_found_rows();
			
			return array('results' => $results, 'total_record' => $total_record);
		}
  }
?>